package com.minyifang.wcspf.work.ui.user.presenter;

import com.google.gson.Gson;
import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.common.md5.SafeUtils;
import com.minyifang.wcspf.common.utils.LogUtil;
import com.minyifang.wcspf.work.ui.user.model.CouponNumBean;
import com.minyifang.wcspf.work.ui.user.view.MyCouponView;
import com.minyifang.wcspf.work.ui.user.view.MyWalletView;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class MyCouponPresenter extends BasePresenter<MyCouponView> {

    public void getCouponNum() {

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), Constants.getJsonData(null, UserManager.getInstance().getToken()).toString());

        addTask(RetrofitHelper.getInstance().getService().getCouponNum(requestBody), respond -> {
            if (respond.result == 1) {
                LogUtil.e("购物券数量："+SafeUtils.decrypt(respond.data));
                CouponNumBean bean = new Gson().fromJson(SafeUtils.decrypt(respond.data), CouponNumBean.class);
                getView().showCouponNum(bean);
            } else
                getView().showRequestFailed(respond.message);
        });

    }
}
